package day1101_2;

import java.io.*;

//ObjectOutputStream类的方法()将   Student对象写到文件中
class Student  implements Serializable { String name;}  //将游戏中某个人物存档(存到文件)
public class S1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos=//1.创建对象输出流
                new ObjectOutputStream( new FileOutputStream("oo.txt"));

        Student zs=new Student();    zs.name="张三";
        oos.writeObject(zs);//2.用对象输出流的writeObject方法将学生对象写出到文件

        oos.close();//3.关闭对象输出流ObjectOutputStream(释放对应的oo.txt)



        ObjectInputStream ois=//1.创建对象输出流
                new ObjectInputStream( new FileInputStream("oo.txt"));

        Student s=(Student) ois.readObject();//2.用对象输出流的writeObject方法将学生对象写出到文件
        System.out.println(s.name);

        ois.close();//3.关闭对象输出流ObjectOutputStream(释放对应的oo.txt)

    }
}